<template>  <!--领用审核-->
  <el-dialog
    :title="!dataForm.receiveId ? '领用审核' : '领用审核'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm"  ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="资产名" prop="assetsName">
            <el-input v-model="dataForm.assetsName" placeholder="资产名" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="资产编号" prop="assetsNum">
            <el-input v-model="dataForm.assetsNum" placeholder="资产编号" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="领用人" prop="userName">
            <el-input v-model="dataForm.userName" placeholder="领用人" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="领用日期" prop="receiveTime">
            <el-input v-model="dataForm.receiveTime" placeholder="领用日期" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="审核结果" prop="assetsStatus">
        <el-radio v-model="dataForm.createStatus" :label="1" >同意</el-radio><!--&lt;!&ndash;// 0领用审核中 1使用中 2维修中 3 报废 4领用失败  5 维修失败  6 归还成功-->
        <el-radio v-model="dataForm.createStatus" :label="4">不同意</el-radio>     <!--//     * 7归还审核   8报修审核&ndash;&gt;-->
      </el-form-item>
      <el-form-item label="备注" prop="receiveDesc">
        <el-input v-model="dataForm.autitorChange" placeholder="备注" ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        receiveId: 0,
        assetsName: '',
        assetsNum: '',
        userName: '',
        receiveTime: '',
        createBy: '',   // 领用审核人
        createTime: '',   // 审核时间
        receiveDesc: '',  // 领用申请说明
        createStatus: 1, // 默认审核选择通过
        autitorDesc: '',  // 领用审核意见
        autitorDesc2: '',  // 报修审核意见
        createBy2: '',  // 报修审核人
        createTime2: '', // 报修审核时间
        repairsDesc: '',  // 维修说明
        autitorChange: '',
        repairsPic: ''
      },
      dataRule: {
      }
    }
  },
  methods: {
    init (id) {
      this.dataForm.receiveId = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.receiveId) {
          this.$http({
            url: this.$http.adornUrl(`/assets/receive/info/${this.dataForm.receiveId}`),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              // console.log('data' + data.receive.userName)
              this.dataForm.assetsName = data.receive.assetsName
              this.dataForm.assetsNum = data.receive.assetsNum
              this.dataForm.userName = data.receive.userName
              this.dataForm.receiveTime = data.receive.receiveTime
              this.dataForm.createBy = data.receive.createBy
              this.dataForm.createTime = data.receive.createTime
              this.dataForm.receiveDesc = data.receive.receiveDesc
              this.dataForm.repairsPic = data.receive.repairsPic
              /* this.dataForm.createStatus = data.receive.createStatus */
            }
          })
        }
      })
    },
    //  获得当前时间
    getCurrentTime () {
      return new Date()
    },
    // 审核表单提交
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/assets/receive/autitorSave'),
            method: 'post',
            data: this.$http.adornData({
              'receiveId': this.dataForm.receiveId || undefined,
              'assetsNum': this.dataForm.assetsNum,   // 资产编号
              'assetsName': this.dataForm.assetsName,   // 资产名字
              'userName': this.dataForm.userName,     //  资产领用人
              'receiveTime': this.dataForm.receiveTime,   // 领用时间
              'createBy': this.$store.state.user.name,  // 领用审核人
              'createTime': this.getCurrentTime(),   // 领用审核时间
              'createStatus': this.dataForm.createStatus,  // 审核状态  未禁用
              'autitorChange': this.dataForm.autitorChange  // 公用审核意见中
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>
